<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>公众号授权</title>
		<link href="https://cdn.bootcdn.net/ajax/libs/weui/2.3.0/style/weui.css" rel="stylesheet">
		<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
		<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
		<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>
		<style>
			body {
				background-color: #f3f3f3;
			}

			.container {
				padding: 12px;
			}

			.vertifyCodeInput {
				flex: 1;
			}

			.vertifyCodeBtn {
				width: 90px;
				font-size: 14px;
				line-height: initial;
				padding: 8px 4px;
				margin: 0 4px;
			}

			.submitBtnContainer {
				text-align: center;
				display: flex;
				justify-content: center;
			}

			.submitBtn {
				background-color: #f18c17;
				margin: 12px 0;

			}

			.imgContainer {
				text-align: center;
				padding: 30% 0;
			}

			.imgContainer img {
				width: 20%;
				height: 20%;
				animation: turn 5s linear infinite;
			}

			@keyframes turn {
				0% {
					-webkit-transform: rotate(0deg);
				}

				25% {
					-webkit-transform: rotate(-90deg);
				}

				50% {
					-webkit-transform: rotate(-180deg);
				}

				75% {
					-webkit-transform: rotate(-270deg);
				}

				100% {
					-webkit-transform: rotate(-360deg);
				}
			}
		</style>
	</head>

	<body>
		<div class="imgContainer">
			<img src=""
			 alt="">
		</div>
		<div id="dialogs">
			<div class="js_dialog" id="iosDialog1" style="display: none;">
				<div class="weui-mask"></div>
				<div class="weui-dialog">
					<div class="weui-dialog__hd"><strong class="weui-dialog__title dialogTitle"></strong></div>
					<div class="weui-dialog__bd dialogContent"></div>
					<div class="weui-dialog__ft">
						<a href="javascript:" class="weui-dialog__btn weui-dialog__btn_default dialogOpe"></a>
					</div>
				</div>
			</div>
		</div>

		<script>
			var baseUrl = 'https://app.aptenon.com/crm'
			var curUrl = location.href
			var urlParams = curUrl.split('?')[1]
			var code = ''
			var WxOpenId = ''
			var urlParamsObj = {}
			var mpOpenId = ''

			if (urlParams) {
				var urlParamsArr = urlParams.split('&')
				for (var i = 0; i < urlParamsArr.length; i++) {
					var str = urlParamsArr[i].split('=')
					urlParamsObj[str[0]] = str[1]
				}
			}

			let redirectUrl = curUrl.split('?')[0]

			if (urlParamsObj.mpOpenId) {
				mpOpenId = urlParamsObj.mpOpenId
				redirectUrl = redirectUrl + '?mpOpenId=' + mpOpenId
			}

			if (urlParamsObj.code) {
				code = urlParamsObj.code
			} else {
				location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxdac90ea64e64dcfc&redirect_uri=" +
					redirectUrl + "&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect"
			}

			document.addEventListener('UniAppJSBridgeReady', function() {
				console.log('uniready')
				uni.getEnv(function(res) {
					console.log('当前环境：' + JSON.stringify(res));
					uni.postMessage({
						data: {
							code: code
						}
					});
					uni.redirectTo({
						url:'/agentPages/agent/agentIndexWx?code='+code
					})
				});
			});

			function openDialog(title, content, ope, cb) {
				title = title || ''
				content = content || ''
				ope = ope || '确定'
				$('.dialogTitle').html(title);
				$('.dialogContent').html(content);
				$('.dialogOpe').html(ope);
				$('#iosDialog1').show();
				$('.dialogOpe').one('click', function(e) {
					e.preventDefault();
					$('#iosDialog1').hide()
					if (cb) {
						cb()
					}
				});
			}
		</script>
	</body>

</html>
